package app.fugema.shop.main.evaluate.vm;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.base.common.model.http.jackSon.JacksonUtils;
import com.base.common.netBeanPackage.BaseApiResult;
import com.base.common.netBeanPackage.BaseResponse;
import com.base.common.netBeanPackage.LiveDataWrapper;
import com.base.common.viewmodel.BaseViewModel;
import app.fugema.shop.http.HttpService;
import app.fugema.shop.main.evaluate.model.AnswerResult;
import app.fugema.shop.main.evaluate.model.CommentJosnParam;
import app.fugema.shop.main.evaluate.model.EvaluateDataCountBean;
import app.fugema.shop.main.evaluate.model.CommentProductResult;
import app.fugema.shop.main.evaluate.model.GoodsComment;
import app.fugema.shop.main.evaluate.model.CommentListResult;
import app.fugema.shop.main.evaluate.model.QusetionResult;
import app.fugema.shop.main.setting.model.UploadPicResult;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class EvaluateVM extends BaseViewModel
{

    public EvaluateVM(@NonNull Application application)
    {
        super(application);
    }

    /**
     *  提交订单评论
     * @param orderId
     * @param comments
     * @param userKey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<BaseApiResult>> postAddEvaluate(Long orderId, List<GoodsComment> comments, String userKey)
    {
        /*
        jsonstr={
                "orderId":"2021070861190611",
            "serviceMark":"3",
            "deliveryMark":"5",
            "packMark":"3",
            "productComments":[
        {
            "mark":"2",
                "content":"测试提交表评论",
                "orderItemId":245,
                "images":[
            "/temp/20210709113836269252.png"
   ],
            "wxmediaId":[

   ]
        }
 ]
}*/
        CommentJosnParam josnParam = new CommentJosnParam();
        josnParam.setOrderId( String.valueOf( orderId ) );
        // 默认评分 都是 5
        josnParam.setServiceMark("5");
        josnParam.setDeliveryMark("5");
        josnParam.setPackMark("5");
        josnParam.setProductComments( comments );
        return send(HttpService.getHttpServer().addComment(JacksonUtils.transBean2Json(josnParam),userKey));
    }

    /**
     *  获取待评论商品信息
     * @param orderId
     * @param userKey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<CommentProductResult>> getCommentProductByOder(long orderId, String userKey)
    {
        return send(HttpService.getHttpServer().getCommentByOrderId(orderId, userKey));
    }

    /**
     *  查询 商品评论 列表
     * @param pId
     * @param pn
     * @param type
     * @return
     */
    public MutableLiveData<LiveDataWrapper<CommentListResult>> evaluatePageByProdId(int pId, int pn, int type)
    {
        //commentType  评论类型： 0：所有 默认 1：好评 2：中评 3：差评 4：有图 5：追加
        int pSize = 10;
        return send(HttpService.getHttpServer().getCommentByProductId(pId, pn, pSize, type));
    }

    /**
     *  上传图片
     * @param picBase64Str
     * @return
     */
    public MutableLiveData<LiveDataWrapper<UploadPicResult>> upLoadPIc(String picBase64Str)
    {
        return send(HttpService.getHttpServer().upLoadPIc(picBase64Str));
    }

    //问问 大家 相关 接口

    /**
     *  根据 商品ID 查询 问问大家 列表
     * @param prodId
     * @param pn
     * @return
     */
    public MutableLiveData<LiveDataWrapper<QusetionResult>> getQuestionByProductId(int prodId,int pn)
    {
        Map<String,Object> params = new HashMap<>();
        params.put("id",prodId);
        params.put("pageIndex",pn);
        params.put("pageSize",10);
        return send(HttpService.getHttpServer().getQuestion(params));
    }


    /**
     *  查询问题详情
     * @param questionId
     * @return
     */
    public MutableLiveData<LiveDataWrapper<AnswerResult>> getQuestionDetailById(int questionId)
    {
        return send(HttpService.getHttpServer().getQuestionDetail(questionId));
    }

    /**
     *  添加 一个问题
     * @param productId
     * @param userId
     * @param title
     * @return
     */
    public MutableLiveData<LiveDataWrapper<BaseApiResult>> applyQuestion(int productId,int userId,String title)
    {
        return send(HttpService.getHttpServer().postQuestion(productId, userId, title));
    }

    /**
     *  添加一个 回答
     * @param questId
     * @param userId
     * @param acontent
     * @return
     */
    public MutableLiveData<LiveDataWrapper<BaseApiResult>> applyAnswer(int questId,int userId,String acontent)
    {
        return send(HttpService.getHttpServer().postAnswer(questId, userId, acontent));
    }

    /**
     *  我的问答  根据用户ID 查询问题列表
     * @param userId
     * @param pn
     * @return
     */
    public MutableLiveData<LiveDataWrapper<QusetionResult>> getQuestionByUserId(int userId, int pn)
    {
        Map<String,Object> params = new HashMap<>();
        params.put("id",userId);
        params.put("pageIndex",pn);
        params.put("pageSize",10);
        return send(HttpService.getHttpServer().getQuestionByUser(params));
    }

}
